{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "98e0159f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "经过标准化处理后的数据： [[ 1.51861254 -0.5622498   0.23205254 ...  0.36217728  1.84791957\n",
      "   1.01300893]\n",
      " [ 0.24628963 -0.49941338 -0.82799632 ...  0.40605066  1.1134493\n",
      "   0.96524152]\n",
      " [ 0.19687903  0.02123125  1.10933436 ...  0.31830389  0.78858745\n",
      "   1.39514818]\n",
      " ...\n",
      " [ 0.33275817  1.74474449 -0.38935541 ... -1.61212515 -1.48544548\n",
      "   0.28057537]\n",
      " [ 0.20923168  0.22769377  0.01273209 ... -1.56825176 -1.40069891\n",
      "   0.29649784]\n",
      " [ 1.39508604  1.58316512  1.36520822 ... -1.52437837 -1.42894777\n",
      "  -0.59516041]]\n",
      "Sklearn自带葡萄酒数据集的标签值： [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
      " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEECAYAAAA2xHO4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTA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9vu8IVOBpWb2oJn9FXgRuMTMrjCzy6Nb7w7jZ5vZ+8xsJKF/4udmNtLM9sobJ1IRShQiMZnZqWZ2aid/amZLj8ZU4HUz2ze69XX324E/ACcC/w78CbgVaAKuJJw2ujHax17Am0A/4ATCefHbAR+Jfq+59bak9unbiUg3Rc1wKwjn27ebWSuhG3wNoUN2InA8obMa4DeEtXmWAC8A/d39BTNb32GzlxCW7LgLOA/YFdgMbA9c6O5rk35dIvl0RCFSIjPb38zuBrYB2qOmpv8C9gFeIiy9cSpwN+HoICd3REE0boSZ7UGYisLMTiB0MOPumwlrJZ0MfJLQuDY4ydcl0hUdUYiUZgRwA3C4u681s3HRcgk7ALOB6wnrSh1DmD56rcNzf004ovi7u2+MitQfJaysCvA4IeFMiX4fAOwd3R+WyKsRiUFHFCKlOZMwbbRH9Pu8DkcUuPvTwCYzG0v4oO+YKE4CPgz/WnTuT9H2/hA9dxFhKitnBHBadHtfIq9GJAYdUYiU5kLgf4GZwAe6GDMN+CchUbwenak0kHBBnFHAwcAHgSGEI4zhwN872c4KwlEKhHqHSCqUKERKs97dnzezxWZ2DDAhb+oJd8/VHN7h7m5mBxOSRhvwK8L7bhtgPHAkcIuZfTa67oEBvaJC+WrCdSmIto+ZNbn7pgq8TpF/UaIQicndf9nh/hejD/Osu38gusjNewHM7JPAdODBaOxfgL9Ef9sJ6AsMAj7u7mui8bkGvH6EI40/AsuB73QI4UDCe/Y3Cb1EkU5pUUCRMotWTO3t7svTjkWkHJQoRESkIJ31JCIiBSlRiIhIQUoUIiJSkBKFiIgUpEQhIiIF/X/u0PyJljA8AgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#项目4-项目实训代码\n",
    "\n",
    "from sklearn.datasets import load_wine\n",
    "from sklearn.model_selection import train_test_split \n",
    "from sklearn import preprocessing\n",
    "from sklearn.neighbors import KNeighborsClassifier  \n",
    "from sklearn.model_selection import cross_val_score  #导入交叉验证模块\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#数据标准化处理\n",
    "data=load_wine().data\n",
    "cdata=preprocessing.StandardScaler().fit_transform(data)  \n",
    "\n",
    "#输出数据集的特征变量与标签值，并将数据集拆分为训练集与测试集\n",
    "x,y=cdata,load_wine().target\n",
    "print(\"经过标准化处理后的数据：\",x)\n",
    "print(\"Sklearn自带葡萄酒数据集的标签值：\",y)\n",
    "x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=0,test_size=30) \n",
    "\n",
    "#k取不同值的情况下，模型的预测误差率计算\n",
    "k_range=range(1,15)         #设置k值的取值范围\n",
    "k_error=[]                  #保存预测误差率的数组\n",
    "for k in k_range:\n",
    "    model=KNeighborsClassifier(n_neighbors=k)\n",
    "    scores=cross_val_score(model,x,y,cv=5,scoring='accuracy')#5折交叉验证\n",
    "    k_error.append(1-scores.mean())              \n",
    "\n",
    "#画图，x轴表示k的取值，y轴表示预测误差率\n",
    "plt.rcParams['font.sans-serif']='Simhei'\n",
    "plt.plot(k_range,k_error,'r-')\n",
    "plt.xlabel('k的取值')\n",
    "plt.ylabel('预测误差率')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8bffc003",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "模型预测准确率： 1.0\n",
      "测试集的预测标签： [0 2 1 0 1 1 0 2 1 1 2 2 0 1 2 1 0 0 1 0 1 0 0 1 1 1 1 1 1 2]\n",
      "测试集的真实标签： [0 2 1 0 1 1 0 2 1 1 2 2 0 1 2 1 0 0 1 0 1 0 0 1 1 1 1 1 1 2]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "#k=7时，训练模型\n",
    "model=KNeighborsClassifier(n_neighbors=7)\n",
    "model.fit(x_train,y_train)\n",
    "#对模型进行评估\n",
    "pred=model.predict(x_test)\n",
    "ac=accuracy_score(y_test,pred)\n",
    "print(\"模型预测准确率：\",ac)\n",
    "print(\"测试集的预测标签：\",pred)\n",
    "print(\"测试集的真实标签：\",y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "210fe172",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "新样本的预测标签： [0]\n"
     ]
    }
   ],
   "source": [
    "#对新样本所属类别进行预测\n",
    "import numpy as np\n",
    "\n",
    "x_new=np.array([[13.2,2.77,2.51,18.5,96.6,1.04,2.55,0.57,1.47,6.2,1.05,3.33,820]])\n",
    "pred=model.predict(x_new)\n",
    "print(\"新样本的预测标签：\",pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d924c460",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0da69d24",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
